package io.renren.modules.medical.controller;


import io.renren.common.result.Result;
import io.renren.common.validator.group.AddGroup;
import io.renren.common.validator.group.UpdateGroup;
import io.renren.modules.medical.entity.IllSubEntity;
import io.renren.modules.medical.service.IllSubService;
import io.renren.modules.medical.vo.medicalVo.IllSubAndChildrenVo;
import io.renren.modules.medical.vo.medicalVo.IllSubTitleAndIdVo;
import lombok.RequiredArgsConstructor;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.validation.constraints.NotNull;
import java.util.Arrays;
import java.util.List;

/**
 * 病情分类接口
 * @author luosheng
 * @email luoshengshuai@foxmail.com
 * @date 2023-04-01 10:41:37
 */
@RequiredArgsConstructor
@RestController
@RequestMapping("/medical/illsub")
public class IllSubController {

    private final IllSubService illSubService;

    @GetMapping("/getParentId/{subId}")
    public Result<Long> getParentId(@PathVariable("subId") Long subId){
        return Result.success(illSubService.getById(subId).getParentId());
    }

    /**
     * 获取列表集合和子列表
     */
    @RequiresPermissions("illsub:list")
    @GetMapping("/list/tree")
    public Result<List<IllSubAndChildrenVo>> list(){
        List<IllSubAndChildrenVo> entities = illSubService.listWithTree();
        return Result.success(entities);
    }

    /**
     * 添加患者基础信息 获取一级集合
     * @return result
     */
    @GetMapping("/getOneLevel")
    public Result<List<IllSubTitleAndIdVo>> getOneLevel(){
        List<IllSubTitleAndIdVo> oneLevelList = illSubService.getOneLevelList();
        return Result.success(oneLevelList);
    }

    /**
     * 基本信息添加获取二级分类
     * @return result
     */
    @GetMapping("/getBasicTwoList")
    public Result<List<IllSubTitleAndIdVo>> getTwoLevel(){
        List<IllSubTitleAndIdVo> twoLevelList = illSubService.getBasicTwoList();
        return Result.success(twoLevelList);
    }

    /**
     * 获取到当前医生病情分类下的所有病情
     */
    @GetMapping("/getTwoList")
    public Result<List<IllSubTitleAndIdVo>> getTwoList(){
        List<IllSubTitleAndIdVo> twoList = illSubService.getTwoList();
        return Result.success(twoList);
    }

    /**
     * 信息
     */
    @RequiresPermissions("illsub:info")
    @GetMapping("/info/{id}")
    public Result<IllSubEntity> info(@PathVariable("id") Long id){
		IllSubEntity illSub = illSubService.getById(id);
        return Result.success(illSub);
    }

    /**
     * 保存
     */
    @RequiresPermissions("illsub:save")
    @PostMapping("/save")
    public Result<String> save(@Validated(AddGroup.class) @RequestBody IllSubEntity illSub){
		illSubService.saveIllsub(illSub);
        return Result.success(null);
    }

    /**
     * 修改
     */
    @RequiresPermissions("illsub:update")
    @PostMapping("/update")
    public Result<String> update(@Validated(UpdateGroup.class) @RequestBody IllSubEntity illSub){
		illSubService.updateIllsub(illSub);
        return Result.success(null);
    }

    /**
     * 删除
     */
    @RequiresPermissions("illsub:delete")
    @PostMapping("/delete")
    public Result<String> delete(@RequestBody @NotNull Long[] ids){
		illSubService.removeByIds(Arrays.asList(ids));
        return Result.success(null);
    }

}
